/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.util.ArrayList;
import java.util.Observer;

/**
 *
 * @author simply
 */
public class Observable {
    private ArrayList<Observer> observers;
    private boolean changed = false;
    
    public Observable() {
        this.observers = new ArrayList<>();
    }
    
    public void addObserver(Observer o) {
        this.observers.add(o);
    }
    
    public void deleteObserver(Observer o) {
        this.observers.remove(o);
    }
    
    public void notifyObservers() {
        throw new RuntimeException("Este metodo no deberia ser invocado nunca");
        /*
        if (!this.changed) return;
        this.changed = false;
        
        for (Observer obs : this.observers) {
            obs.update(null, null);
        }
        */
    }
    
    public void deleteObservers() {
        this.observers.clear();
    }
    
    public void setChanged() {
        throw new RuntimeException("Este metodo no deberia ser invocado nunca");
        //this.changed = true;
    }
    
    public void clearChanged() {
        throw new RuntimeException("Este metodo no deberia ser invocado nunca");
        //this.changed = false;
    }
    
    public boolean hasChanged() {
        return this.changed;
    }
    
    public int countObservers() {
        return this.observers.size();
    }
}
